package com.frank.controller;

import com.frank.dto.JsonResult;
import com.frank.model.Resume;
import com.frank.service.ResumeService;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author frank
 */
@RestController
@RequestMapping("/resume")
public class ResumeController {

    @Resource
    private ResumeService resumeService;

    @RequestMapping(value = "/getByUserId", method = RequestMethod.GET)
    public JsonResult<?> getByUserId(@RequestParam("userId") Integer userId) {
        Resume resume = resumeService.getResumeByUserId(userId);
        return new JsonResult<>(200,"获取简历成功",resume);
    }

    @RequestMapping(value = "/getByInterviewId", method = RequestMethod.GET)
    public JsonResult<?> getByInterviewId(@RequestParam("interviewId") Integer interviewId) {
        List<Resume> resumeList = resumeService.getResumeListByInterviewId(interviewId);
        return new JsonResult<>(200,"获取简历成功",resumeList);
    }

    @RequestMapping(value = "/getByRecruitType", method = RequestMethod.GET)
    public JsonResult<?> getByRecruitType(@RequestParam("recruitType") String recruitType) {
        List<Resume> resumeList = resumeService.getResumeListByRecruitType(recruitType);
        return new JsonResult<>(200,"获取简历成功",resumeList);
    }

    @Transactional
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public JsonResult<?> addResume(@RequestBody Resume resume) {
        if (resumeService.insertResume(resume)){
            return new JsonResult<>(200,"新增简历成功");
        }else {
            return new JsonResult<>(500,"新增简历失败");
        }
    }

    @Transactional
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public JsonResult<?> updateResume(@RequestBody Resume resume) {
        if (resumeService.updateResume(resume)){
            return new JsonResult<>(200,"修改简历成功");
        }else {
            return new JsonResult<>(500,"修改简历失败");
        }
    }
}
